using System;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace XFNRelationsPlugIn
{
    //[WriterPlugin( "F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72", "Smart HelloWorld", 
    //    ImagePath = "Images.InsertHelloWorld.png",
    //    PublisherUrl = "http://www.microsoft.com",
    //    Description = "Embed Smart Hello World in your blog posts.")]

    //[InsertableContentSource( "Smart Hello World" )]
	public class SmartXFNRelationsPlugin : SmartContentSource
	{
		private XFNRelationsSettings _defaultSettings;
		public SmartXFNRelationsPlugin()
		{
		}

		public override void Initialize(IProperties pluginOptions)
		{
			base.Initialize(pluginOptions);

			_defaultSettings = new XFNRelationsSettings(pluginOptions) ;
		}

		public override SmartContentEditor CreateEditor(ISmartContentEditorSite contentEditorSite)
		{
			return new SmartXFNRelationsContentEditor(contentEditorSite, _defaultSettings) ;
		}

		public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
		{
			XFNRelationsSettings settings = new XFNRelationsSettings(newContent.Properties);
			using (XFNRelationsInsertForm insertForm = new XFNRelationsInsertForm())
			{
				insertForm.Message = _defaultSettings.Message;
				DialogResult result = insertForm.ShowDialog();
				if(result == DialogResult.OK)
					settings.Message = insertForm.Message;
				return result;
			}
		}

		public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext )
		{
			XFNRelationsSettings settings = new XFNRelationsSettings(content.Properties);
			return String.Format("<h3>{0}</h3>", settings.Message);
		}
	}
}